package com.toommi.refuse.controller;

import com.toommi.refuse.common.response.CommonResponse;
import com.toommi.refuse.model.WeightGatherModel;
import com.toommi.refuse.service.WeightGatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * ..
 * 汇总称重记录
 *
 * @author yangg
 * @since 2019-08-05 18:02
 */
@RestController
@RequestMapping(value = "")
@Slf4j
@AllArgsConstructor
@Api(tags = "汇总称重")
public class WeightGatherController {

    private WeightGatherService gatherService;

    /**
     * 新增汇总称重记录，APP端上报
     *
     * @param model 汇总称重记录详情,date格式为yyyy-mm-dd
     * @return 上报结果
     */
    @ApiOperation(value = "APP端上报汇总称重记录", notes = "APP端上报汇总称重记录")
    @ApiImplicitParam(name = "model", value = "汇总称重详情", required = true, dataType = "WeightGatherModel")
    @PostMapping(value = "/api/weight/gather", produces = "application/json;charset=UTF-8")
    public CommonResponse addWeightGather(@RequestBody WeightGatherModel model) {

        CommonResponse commonResponse = CommonResponse.success();

        try {
            gatherService.addWeightGather(model);
        } catch (Exception e) {
            log.error("add weight gather error:{}", e);
            commonResponse = CommonResponse.serverError();
        }

        return commonResponse;
    }

    /**
     * 获取指定app操作员在指定日期的汇总称重信息
     *
     * @param appUserId app操作员id
     * @param date      日期时间，格式为yyyy-mm-dd
     * @return 汇总称重信息
     */
    @ApiOperation(value = "获取指定用户指定日期的汇总称重信息", notes = "获取指定用户指定日期的汇总称重信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appUserId", value = "app操作员id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "date", value = "日期时间，格式为yyyy-mm-dd", required = true, dataType = "String")
    })
    @GetMapping(value = "/api/weight/gather", produces = "application/json;charset=UTF-8")
    public CommonResponse findWeightGather(long appUserId, String date) {

        CommonResponse commonResponse = CommonResponse.success();
        try {
            commonResponse.setData(gatherService.findWeightGather(appUserId, date));
        } catch (Exception e) {
            log.error("get weight gather error:{}", e);
            commonResponse = CommonResponse.serverError();
        }

        return commonResponse;
    }


}
